package com.dandan.testcollection;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.dandan.testcollection.bean.KLineBean;
import com.dandan.testcollection.bean.NameBean;
import com.dandan.testcollection.httprequest.HttpApi;
import com.dandan.testcollection.httprequest.OnResponsListener;
import com.dandan.testcollection.touch.TouchTestActivity;
import com.dandan.testcollection.view.KLine;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private KLine kline;
    private String url = "http://api.jinse.com/v3/market/kline?currency_type=btc&exchange_type=huobipro&period=1H&currency=CNY";
    private String newUrl = "http://api.jinse.com/v3/coin/trend?slugs=bitcoin&start_time=&end_time=&version=3.1.0&source=android";

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        kline = findViewById(R.id.kline);

        httpRequest();

        Intent intent = new Intent(MainActivity.this,TouchTestActivity.class);
        startActivity(intent);
    }

    private void httpRequest() {
        HttpApi.generalRequest(url, true, MainActivity.this, null, null, new OnResponsListener() {
            @Override
            public void onSuccess(String body) {
                Gson gson = new Gson();
                KLineBean kLineBean = gson.fromJson(body, KLineBean.class);
                kline.setData(kLineBean)
//                        .setColor(Color.parseColor("#ff0000"))
                        .setShowTopPoint(false)
                        .setShowLeftNumber(false)
                        .setOnCurrentPriceListener(new KLine.OnCurrentPriceListener() {
                            @Override
                            public void onCurrentPrice(String time, Double price) {
                                System.out.print(time);
                                System.out.println(price);
                                System.out.println("---------------------");
                            }
                        })
                ;
                

            }

            @Override
            public void onField(String body) {

            }
        });
    }

}
